/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gameheart.client.logic;

import gameheart.client.sprite.ImageResposity;
import gameheart.client.sprite.ImageSprite;
import gameheart.client.sprite.LabelSprite;
import gameheart.client.sprite.Sprite;
import gameheart.transport.MyException;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author win7
 */
public class WaitUserState extends State {

    public ImageResposity _imageResposity;

    public WaitUserState(MainGame mainGame) {
        super(mainGame);
    }

    public void gameUpdate() {
        try {
            _mainGame.getAdapter().processMessage();
        } catch (MyException ex) {
            Logger.getLogger(WaitUserState.class.getName()).log(Level.SEVERE, null, ex);
        }
        String userNames[] = _mainGame.getAdapter().getUserNames();
        for(int index = 0; index < userNames.length; ++index)
        {
            int playerIndex = (index + 4 - _mainGame.getAdapter().getCurrentUserId()) % 4;
            _names[playerIndex]._text = userNames[index];
        }
        if (_mainGame.getAdapter().IsStartGame()) {
            _mainGame.ChangeGameState(GameStateIds.PlayStateId);
        }
    }
    int[] _Xs = {900, 2, 385, 735};
    int[] _Ys = {150, 430, 103, 430};

    public void gameRender(Graphics g) {
        _bg.draw(g);
        for (int index = 0; index < _names.length; ++index) {
            _names[index].draw(g);
        }
    }
    ArrayList<Sprite> sprite = new ArrayList<Sprite>();
    ImageSprite _bg;
    ImageResposity imageResposity;
    private LabelSprite _names[] = new LabelSprite[4];

    public void gameInit() {
                _imageResposity = new ImageResposity();
        _bg = new ImageSprite(0, 0, 1024, 708, _imageResposity, "bg_main.jpg");
        BufferedImage image = _imageResposity.getImage("NewTextBox.jpg");
        String userName[] = _mainGame.getAdapter().getUserNames();
        for (int index = 0; index < 4; ++index) {
            int playIndex = (index + 4 - _mainGame.getAdapter().getCurrentUserId()) % 4;
            _names[playIndex] = new LabelSprite(_Xs[playIndex], _Ys[playIndex], 80, 30, _mainGame.getAdapter().getUserName(index), image);
            //_names[index] = new LabelSprite(_Xs[index], _Ys[index], 80, 30, _mainGame.getAdapter().getUserName(index), image);
        }
    }

    public void gameEnd() {
    }

    public void mouseClicked(MouseEvent e) {
    }

    public void keyPressed(KeyEvent e) {
    }
}
